<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        label {
            font-weight: normal;
        }
    </style>
</head>
<body>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-admin-role-add">
        <div class="form-group">
            <label class="control-label col-xs-4 col-sm-3">角色名称：</label>
            <div class="formControls col-xs-4 col-sm-4">
                <input type="text" class="form-control" value="" placeholder="必填项" id="roleNames" name="roleName">
            </div>
        </div>
        <input value="2" name="roleType" style="display: none"/>
        <div class="form-group">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input onclick="bizRolesubmit();return false;" class="btn btn-primary radius" type="submit"
                       value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
            </div>
        </div>
    </form>
</article>
<script>
    //角色管理，添加角色功能，提交按钮
    function bizRolesubmit() {
        //验证
        var roleNames = $("#roleNames").val();
        if (roleNames == null || roleNames == undefined || roleNames == "") {
            layer.alert("角色名称不能为空！", {icon: 0});
            return false;
        }

        //提交
        $.ajax({
            type: "GET",
            url: "menu/insertBizRole",
            data: $("#form-admin-role-add").serialize(),
            dataType: "json",
            success: function (data) {
                //state为true，新增成功
                if (data.state) {
                    layer.msg(data.message, {icon: 1});
                    //关闭新增窗口
                    removeIframe();

                    //重新查询一次表格数据
                    $.ajax({
                        type: "get",
                        url: "menu/getAllBizRole",
                        dataType: "json",
                        success: function (json) {
                            $("#bizRoleTable").bootstrapTable('load', json);
                        }
                    })
                }

            },
            error: function () {
                alert("error");
            }
        });
    }
    $(function () {
        $(".permission-list dt input:checkbox").click(function () {
            $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function () {
            var l = $(this).parent().parent().find("input:checked").length;
            var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if ($(this).prop("checked")) {
                $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
            }
            else {
                if (l == 0) {
                    $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
                }
                if (l2 == 0) {
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
                }
            }
        });

        $("#form-admin-role-add").validate({
            rules: {
                roleName: {
                    required: true,
                },
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                $(form).ajaxSubmit();
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        });
    });
</script>
</body>
</html>